home *** CD-ROM | disk | FTP | other *** search
/ Australian Personal Computer 2003 July / CD 2 Debian 3.0r1 / Debian.iso / isolinux / root.bin / root / sbin / update-modules < prev   
Encoding:
Text File  |  2002-02-04  |  4.1 KB  |  192 lines

  1. #!/bin/sh
  2. #
  3. # This is the update-modules script for Debian GNU/Linux.
  4. # Copyright 1998-2001 Wichert Akkerman <wakkerma@debian.org>
  5. # Licensed under the GNU GPL, version 2
  6. #
  7.  
  8. MODCONFFILE=/etc/modules.conf
  9. MODCONFTMPFILE="${MODCONFFILE}.$$"
  10. CHANDEVFILE=/etc/chandev.conf
  11. CHANDEVTMPFILE="${CHANDEVFILE}.$$"
  12.  
  13. ARCHDIR=/etc/modutils/arch
  14. HEADER="### This file is automatically generated by update-modules"
  15.  
  16. set -e
  17.  
  18. if [ "$1" = "force" ] ; then
  19.     force=1
  20. else
  21.     force=
  22. fi
  23.  
  24. # Reset the sorting order since we depend on it
  25. LC_COLLATE=C
  26. export LC_COLLATE
  27.  
  28. depdir()
  29. {
  30.     dep=`grep '[[:space:]]*depfile' "${MODCONFFILE}" | tail -n 1 | sed -e 's/depfile=//' -e 's,/[^/]*$,,'`
  31.     if [ -z "$dep" ] ; then
  32.         dep="/lib/modules/`uname -r`"
  33.     fi
  34.  
  35.     echo $dep
  36. }
  37.  
  38. arch() {
  39.     local model=`uname -m`
  40.     case $model in
  41.         i[0-9]86) model=i386; ;;
  42.         sun4u) model=sparc64; ;;
  43.         arm*) model=arm; ;;
  44.         ppc) model=powerpc; ;;
  45.     esac
  46.     echo $model
  47. }
  48.  
  49. archmodel() {
  50.     local arch=`arch`
  51.     local model=""
  52.     if [ $arch = "m68k" ]; then
  53.         if [ -f /proc/hardware ]; then
  54.             model=`sed -ne 's/^Model:[[:space:]]*//p' /proc/hardware`
  55.             case $model in
  56.                 Atari*) model="atari"; ;;
  57.                 Amiga*) model="amiga"; ;;
  58.                 Macintosh*) model="mac"; ;;
  59.                 Motorola*) model="MVME"; ;;
  60.                 *) model="generic"; ;;
  61.             esac
  62.             model=".${model}"
  63.         else
  64.             echo "/proc/hardware does not exist, assuming general m68k system"
  65.             model=".generic"
  66.         fi
  67.     elif [ $arch = "powerpc" ]; then
  68.         if [ -f /proc/cpuinfo ]; then
  69.             model=`sed -ne 's/^machine[[:space:]]*:[[:space:]]*//p' /proc/cpuinfo`
  70.             case $model in
  71.                 Amiga*) model="apus"; ;;
  72.                 Power*) model="pmac"; ;;
  73.                 *) model="generic"; ;;
  74.             esac
  75.             model=".${model}"
  76.         else
  77.             echo "/proc/cpuinfo does not exist, assuming general powerpc system"
  78.             model=".generic"
  79.         fi
  80.     fi
  81.     echo "${arch}${model}"
  82. }
  83.  
  84. checkoverwrite() {
  85.     local cfgfile="$1"
  86.  
  87.     if [ -f "$cfgfile" ]; then
  88.         if ! sed -ne 1p "$cfgfile" | grep -q "^$HEADER" ; then
  89.             echo "Error: the current $cfgfile is not automatically generated." >&2
  90.             if [ -z "$force" ]; then
  91.                 echo "Use \"update-modules force\" to force (re)generation."
  92.                 exit 1
  93.             else
  94.                 echo "force specified, (re)generating file anyway."
  95.             fi
  96.         fi
  97.     fi
  98. }
  99.  
  100. createfile() {
  101.     cat <<EOF > "$1"
  102. $HEADER"
  103. #
  104. # Please do not edit this file directly. If you want to change or add
  105. # anything please take a look at the files in /etc/modutils and read
  106. # the manpage for update-modules.
  107. #
  108. EOF
  109. }
  110.  
  111. addfile() {
  112.     local src="$1"
  113.     local tgt="$2"
  114.  
  115.     echo "### update-modules: start processing $src" >> "$tgt"
  116.     if [ -x "$src" ]; then
  117.         if !  "$src" >> "$tgt" ; then
  118.             echo "Error while executing $src, aborting" >&2
  119.             exit 1
  120.         fi
  121.     else
  122.         cat "$src" >> "$tgt"
  123.     fi
  124.     cat <<EOF >> "$tgt"
  125.  
  126. ### update-modules: end processing $cfg
  127.  
  128. EOF
  129. }
  130.  
  131.  
  132. if [ "`uname -m`" = "s390" ] ; then
  133.     dochandev=1
  134. fi
  135.  
  136. checkoverwrite "$MODCONFFILE"
  137. [ "$dochandev" ] && checkoverwrite "$CHANDEVFILE"
  138.  
  139. if [ 0 -ne "`id -u`" ]; then
  140.     echo "You have to be root to do this." >&2
  141.     exit 2
  142. fi
  143.  
  144. model=`archmodel`
  145. oldmodel=$model
  146.  
  147. while [ ! -f "${ARCHDIR}/${model}" ]; do
  148.     oldmodel=$model
  149.     model=`echo $oldmodel | sed -e 's/\.[^.]\+//'`
  150.     if [ "$model" = "$oldmodel" ]; then
  151.         break
  152.     fi
  153.     echo "Configuration for $oldmodel not found, trying $model"
  154. done
  155.  
  156. CONF="${ARCHDIR}/${model}"
  157.  
  158. if [ ! -f "$CONF" ]; then
  159.     echo "Architecture-specific modutils configuration not found, using defaults"
  160.     CONF="${ARCHDIR}/generic"
  161. fi
  162.  
  163. [ -e "$MODCONFFILE" ] && cp -f "$MODCONFFILE" "${MODCONFFILE}.old"
  164. [ "$dochandev" -a -e "$CHANDEVFILE" ] && cp -f "$CHANDEVFILE" "${CHANDEVFILE}.old"
  165.  
  166. createfile "$MODCONFTMPFILE"
  167. [ "$dochandev" ] && createfile "$CHANDEVTMPFILE"
  168.  
  169. for cfg in /etc/modutils/* $CONF ; do
  170.     if [ -f "$cfg" ]; then # this check is necesarry to skip /etc/modutils/archs
  171.         if [ "$dochandev" ] && echo $cfg | grep -q '\.chandev$' ; then
  172.             addfile "$cfg" "$CHANDEVTMPFILE"
  173.         elif ! echo $cfg | grep -q '\(\.dpkg-[a-z]*\|~\)$' ; then
  174.             addfile "$cfg" "$MODCONFTMPFILE"
  175.         fi
  176.     fi
  177. done
  178.  
  179. mv "$MODCONFTMPFILE" "$MODCONFFILE"
  180. [ "$dochandev" ] && mv "$CHANDEVTMPFILE" "$CHANDEVFILE"
  181.  
  182. # We also call depmod here to stop insmod from complaining that modules.conf
  183. # is more recent then modules.dep
  184. #
  185. if [ -d "`depdir`" -a -f /proc/modules ]
  186. then
  187.     depmod -a || true
  188. fi
  189.  
  190. exit 0
  191.  
  192.